#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
/*
    1. 判断两个区间是否有交集，max>min
    2. 如果有交集，判断交集的大小
*/
struct time_c
{
    int a;
    int b;
    vector<int> conflct;
    time_c(int aa, int bb)
    {
        a = aa;
        b = bb;
    }
};

bool compare1(int a, int b)
{
    return a > b;
}
int main()
{
    int n, a, b, res = 0;
    cin >> n;
    vector<time_c> time_class;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a >> b;
        time_class.push_back(time_c(a, b));
    }
    for (size_t i = 0; i < n-1; i++)
    {
        for (size_t j = i + 1; j < n; j++)
        { // 与每个区间进行比较，看是否有冲突
            if (time_class[i].b > time_class[j].a && time_class[i].b > time_class[j].b)
            { // 说明有冲突,两种情况.第一种情况[1,3],[1,2]
                time_class[i].conflct.push_back(time_class[j].b - time_class[j].a + 1);
            }
            else if (time_class[i].b > time_class[j].a && time_class[i].b < time_class[j].b)
            { // 第一种情况[1,3],[1,5]
                time_class[i].conflct.push_back(time_class[i].b - time_class[j].a + 1);
            }
            else
                continue;
        }
        sort(time_class[i].conflct.begin(), time_class[i].conflct.end(), compare1);
        if (!time_class[i].conflct.empty() && time_class[i].conflct[0] > res)
        {// 找到最大值
            res = time_class[i].conflct[0];
        }
    }
    cout << res;
}